import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:landlore/customWidget/yearMonthCupPicker.dart';
import 'package:landlore/screens/roomManageScreen.dart';

import '../screens/recordScreen.dart';
import 'iosStyleCalendar.dart';

class TitleTab extends StatelessWidget {
  final Function callback;
  final Function popCallback;

  //当前选中的 年/月 ,初始化为当前时间
  final int currentYear;
  final int currentMonth;

  TitleTab(
      {super.key,
      required this.callback,
      required this.currentYear,
      required this.currentMonth,
      required this.popCallback});

  // String selectedDate = "${DateTime.now().year}.${DateTime.now().month}月";

  //缓存区数据,确定后才使用
  late String selectedDateTemp;
  late int currentYearTemp = DateTime.now().year;
  late int currentMonthTemp = DateTime.now().month;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: 50.h),
      color: const Color(0xffe9c46a),
      // 个人资料内容
      // color: const Color(0xffe9c46a),
      child: Column(
        children: [
          SizedBox(
            width: 330.w,
            height: 90.h,
            child: Row(
              children: [
                SizedBox(
                    width: 80.w,
                    height: 80.w,
                    child: Image.asset('assets/images/landloreLogo.png',)),
                Center(
                  // child: AnimatedTextKit(
                  //   pause: const Duration(milliseconds: 0),
                  //   repeatForever: true,
                  //   animatedTexts: [
                  //     RotateAnimatedText('租樂',
                  //         textStyle: TextStyle(
                  //             fontSize: 80.sp,
                  //             // fontWeight: FontWeight.bold,
                  //             color: const Color(0xff264653),
                  //             fontFamily: "游龙行书",
                  //           letterSpacing: 25.w,
                  //         ),
                  //         duration: const Duration(seconds: 10)),
                  //     RotateAnimatedText(
                  //       'LandlorE',
                  //       textStyle: TextStyle(
                  //           fontSize: 80.sp,
                  //           fontWeight: FontWeight.bold,
                  //           color: const Color(0xff264653),
                  //           fontFamily: "islandMoments"),
                  //       duration: const Duration(seconds: 10),
                  //     ),
                  //   ],
                  // ),
                  child:Text(
                    "LandlorE",
                    style: TextStyle(
                        fontSize: 80.sp,
                        fontWeight: FontWeight.bold,
                        color: const Color(0xff264653),
                        fontFamily: "islandMoments"),
                  ),
                ),
              ],
            ),
          ),
          SizedBox(
            height: 25.h,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Column(
                children: [
                  Container(
                    height: 42.h,
                    margin: EdgeInsets.only(left: 40.w, bottom: 15.h),
                    child: ElevatedButton(
                      style: ButtonStyle(
                          backgroundColor: MaterialStateProperty.all(
                              const Color(0xff0077b6)),
                          elevation: MaterialStateProperty.all(9),
                          shape: MaterialStateProperty.all(
                              RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(20.r)))),
                      onPressed: () {
                        Navigator.push(
                            context,
                            MaterialPageRoute(
                                builder: (context) => RecordScreen(
                                    currentYear: currentYear,
                                    currentMonth: currentMonth)));
                      },
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.end,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Icon(
                            Icons.savings_outlined,
                            size: 35.sp,
                            color: Colors.white,
                          ),
                          Text(
                            '账本',
                            style: TextStyle(
                                color: Colors.white70, fontSize: 20.sp),
                          )
                        ],
                      ),
                    ),
                  ),
                  Container(
                    height: 42.h,
                    margin: EdgeInsets.only(left: 40.w),
                    child: ElevatedButton(
                      style: ButtonStyle(
                          backgroundColor: MaterialStateProperty.all(
                              const Color(0xff0077b6)),
                          elevation: MaterialStateProperty.all(9),
                          shape: MaterialStateProperty.all(
                              RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(20.r)))),
                      onPressed: () async {
                        await Navigator.push(
                          context,
                          MaterialPageRoute(
                              builder: (context) => RoomManageScreen()),
                        );
                        popCallback();
                      },
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.end,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Icon(
                            Icons.add_business_rounded,
                            size: 35.sp,
                            color: Colors.white,
                          ),
                          Text(
                            '管理',
                            style: TextStyle(
                                color: Colors.white70, fontSize: 20.sp),
                          )
                        ],
                      ),
                    ),
                  )
                ],
              ),
              Container(
                height: 100.h,
                margin: EdgeInsets.only(right: 60.w),
                child: GestureDetector(
                    onTap: () {
                      showModalBottomSheet(
                          context: context,
                          builder: (context) {
                            return SizedBox(
                              height: 350.h,
                              child: Column(
                                children: [
                                  Expanded(
                                    child: YearMonthCupPicker(
                                      callback: (value, year, month) {
                                        selectedDateTemp = value;
                                        currentYearTemp = year;
                                        currentMonthTemp = month;
                                      },
                                      inputYear: currentYear,
                                      inputMonth: currentMonth,
                                    ),
                                  ),
                                  CupertinoButton(
                                      child: Text(
                                        "确定",
                                        style: TextStyle(
                                            fontSize: 25.sp,
                                            backgroundColor: Colors.white),
                                      ),
                                      onPressed: () {
                                        callback(
                                            currentYearTemp, currentMonthTemp);
                                        // setState(() {
                                        //   currentYear = currentYearTemp;
                                        //   currentMonth= currentMonthTemp;
                                        // });
                                        Navigator.pop(context);
                                      })
                                ],
                              ),
                            );
                          });
                    },
                    child: IosStyleCalendar(
                        year: currentYear, month: currentMonth)),
              ),
            ],
          )
        ],
      ),
    );
  }
}
